function Phi = Kmeans(X,K,num_ite)
% Phi: DxK

[D,N] = size(X);
[a,b] = sort(rand(1,N));
Phi = X(:,b(1:K));

C =  zeros(1,N);

for i = 1:num_ite
    magPhi = sum(Phi.^2,1);
    for n = 1:N
        [t1,C(n)] = min(magPhi - 2*X(:,n)'*Phi);
    end
    for k = 1:K
        idx = find(C==k);
        Phi(:,k) = mean(X(:,idx),2);
    end
end